#-*- coding: utf-8 -*-
import set_app_evn
from set_app_evn import BASE_DIR

import ai
import Image, ImageFilter, ImageEnhance

def register(opener):
    reg_info = {
        'user': 'aksdj990sddddf',
        'passwd': 'wushiyito',
        'passwdAgain': 'wushiyito',
        'answer': 'asdfasdfa',

        'question': 'sadfasdf',
        'questionbak': 'sadfasdf',

        'birthCityId': '2',
        'birthCountyId': '5101',
        'birthProvinceId': '1',
        'birthdayDate': '6',
        'birthdayMonth': '7',
        'birthdayYear': '2002',
        'bru': '',
        'checkbox': 'checkbox',
        'cityId': '2',
        'countyId': '5101',
        'from': '',
        'mailDomain': '@sohu.com',
        'provinceId': '1',
        'sex': '0',
        'textarea': '',
        
        'vcode': 'dksh',
        'vcodeEn': 'lwqIB%2BRTQVn4%2F6fzTSAGyPwTgbIrRlro',
        'xpt': '',
    }
    
    {
        'cfsk': 'RPDBwE5epxPukX0FRCFPnqfwEFV4lH3w',
        'ycka': 'EyJ7uuzzod%2FujWBr377ZBvwTgbIrRlro',
        'ueby': 'oWA7JqpHK%2F%2BlmU%2BQfVsCzoY8BZ60ctPB',
        'xdyb': 'H77Sk8qEEjsrIza58YQvLPwTgbIrRlro',
        'dksh': 'lwqIB%2BRTQVn4%2F6fzTSAGyPwTgbIrRlro',
    }
    #ai.fetch('http://blog.sohu.com/login/reg.do', opener = opener)
    reg_headers = [('Referer', 'http://blog.sohu.com/login/reg.do')]
    res = ai.fetch('http://blog.sohu.com/login/regnew.do', headers = reg_headers, \
                opener = opener, fields = reg_info)
    
    print res['headers'], res['data']
    #http://blog.sohu.com/login/regBlog.do?bru=&domain=asdfsdfsdfa&from=&name=title

def vcode_hack():
    image_name = 'd:/rand.jpg'
    im = Image.open(image_name)
    im = im.filter(ImageFilter.MedianFilter())
    enhancer = ImageEnhance.Contrast(im)
    im = enhancer.enhance(2)
    im = im.convert('1')
    im.show()

if __name__ == '__main__':
    #opener = ai.get_opener()
    #register(opener)
    vcode_hack()
